var buy = function(id,cSellType) 
{ //countPTag(10,1,33); 
	_.go(url.en({act:"check",id:id,cSellType:cSellType},buyUrl));
}
var buy2 = function(id,cSellType)
{ 
	buy(id,cSellType);
}
var showBuyOver = function(obj) 
{
	obj.src=obj.src.replace(".gif","Over.gif"); 
} 
var showBuyOut = function(obj) 
{
	obj.src=obj.src.replace("Over",""); 
}
var showList = function(act)
{
	var p=$("ul#AuctionList");
	$("li",p).removeAttr("class");
	$("li#"+act+"_show",p).addClass("li_here");
	if(act == 'DescShow')
	{//详细信息
		_.e("PctAttr").style.display ="";
		_.e("DescShow").style.display ="";
		_.e("Others").style.display ="none";
		_.e("Commend").style.display ="";
		_.e("SellCredit").style.display ="";
		_.e("CreditShow").style.display ="none";
		_.e("Message").style.display ="";
		_.e("PayMent").style.display ="none";
		$(".title","#Commend").show();
		$(".title","#SellCredit").show();
		$(".title","#CreditShow").show();
		$(".title","#Message").show();
	}else if(act == 'Others')
	{//其他信息
		_.e("PctAttr").style.display ="none";
		_.e("DescShow").style.display ="none";
		_.e("Others").style.display ="";
		_.e("Commend").style.display ="none";
		_.e("SellCredit").style.display ="none";
		_.e("CreditShow").style.display ="none";
		_.e("Message").style.display ="none";
		_.e("PayMent").style.display ="none";		
	}else if(act == 'SellCredit')
	{//销售记录
		_.e("PctAttr").style.display ="none";
		_.e("DescShow").style.display ="none";
		_.e("Others").style.display ="none";
		_.e("Commend").style.display ="none";
		_.e("SellCredit").style.display ="";
		_.e("CreditShow").style.display ="none";
		_.e("Message").style.display ="none";
		_.e("PayMent").style.display ="none";
		$(".title","#SellCredit").hide();
	}else if(act == 'CreditShow')
	{//卖家信用
		_.e("PctAttr").style.display ="none";
		_.e("DescShow").style.display ="none";
		_.e("Others").style.display ="none";
		_.e("Commend").style.display ="none";
		_.e("SellCredit").style.display ="none";
		_.e("CreditShow").style.display ="";
		_.e("Message").style.display ="none";
		_.e("PayMent").style.display ="none";
		$(".title","#CreditShow").hide();
	}else if(act == 'PayMent')
	{//付款方式
		_.e("PctAttr").style.display ="none";
		_.e("DescShow").style.display ="none";
		_.e("Others").style.display ="none";
		_.e("Commend").style.display ="none";
		_.e("SellCredit").style.display ="none";
		_.e("CreditShow").style.display ="none";
		_.e("Message").style.display ="none";
		_.e("PayMent").style.display ="";		
		$(".title","#PayMent").hide();
	}
};

var aValidDuration	= ["dwValidDurationExt_h","dwValidDurationExt_f","dwValidDurationExt_m"];
//时间到,开始出售
var fSateTime = function()
{
	$('#td_buy_button').add('#html_tem_buyButton').show();
	//
	if(!oSaleState)
		fCheck(1);
}
//时间过期
var fTimeOver = function()
{
	for (var i=0;i<aValidDuration.length;i++)
	{
		tmp = _.e(aValidDuration[i]);
		if(typeof tmp == "object") 
			tmp.innerHTML = "商品已下架";
	}
	$('#td_buy_button').add('#html_tem_buyButton').hide();
}
//还没出销时间
var fAfterTime = function()
{
	for (var i=0;i<aValidDuration.length;i++)
	{
		tmp = _.e(aValidDuration[i]);
		if(typeof tmp == "object") 
			tmp.innerHTML = "即将出售";
	}
	$('#td_buy_button').add('#html_tem_buyButton').hide();
}
var fCheck    = function(callback)
{
	//alert(callback);
	if(callback)
		(new Json()).load(url.en({Pact:"statePct",id:id},"shop/dwr.php"),"fCheck");
	return;
}
var fCountDown = function()
{
	if(_.getTime() > _oPct_.uploadDate)
	{
		fSateTime();//时间到,开始出售
		var rs = oTime.write(aValidDuration,_oPct_.dwValidDurationExt);
		if(rs === true)
		{
			arguments.callee.defer(1000,this);
		}else
		{
			fTimeOver();//时间过期
		}
	}else
	{
		fAfterTime();//还没出销时间
		arguments.callee.defer(5000,this);
	}
}
//下面是加载json的程序
var oPLoad = 
{
	init:function()
	{
		fCountDown()//倒记数
		this.commend();
		this.leaveMsg();
		this.creditshow();
		if(_oPct_.cSellType == 1)
		{//一口价
			this.salecredit();
		}else if(_oPct_.cSellType == 2)
		{//拍买
			this.salelog();
			this.price();
		}
		this.shopinfo();
		this.payment();
		this.times();
	},
	//卖家推荐
	commend:function()
	{
		(new Json()).load(url.en({Pact:"commendList",urs:_oPct_.urs},"shop/dwr.php"),"oPLoad.callback_commend");		
	},
	callback_commend:function(o)
	{
		var el = _.e("CommendList_id");
		var rs = [],i,d;
		for(i=0;i<o.length;i++)
		{
			d = o[i];	
			rs.push('<li class="li">');
          		rs.push('<ul>');
          		rs.push('<li class="shopImg">'+Player.image("__return__",80,'','',d["img"],d["url"])+'</li>');
          		rs.push('<li class="shopTitle"><a href="'+d["url"]+'" target="_blank">'+d["sTitle"]+'</a></li>');
          		rs.push('<li class="shopPrize">'+d["dwPrice_bin"]+' 元</li>');
          		rs.push('<li class="shopSell">'+(d['cSellType'] == 1?"一口价":"拍卖")+'</li>');
          		rs.push('</ul>');
          	rs.push('</li>');	
		}
		el.innerHTML = rs.join('');
	},
	//网友留言
	leaveMsg:function()
	{
		//alert((new Json()).en(_oPct_));
		oReview.init({pct:1,id:id,urs:_oPct_.urs});
	},
	//卖家信用
	creditshow:function()
	{
		(new Json()).load(url.en({Pact:"creditShow",urs:_oPct_.urs},"shop/dwr.php"),"oPLoad.callback_creditshow");
	},
	callback_creditshow:function(o)
	{
		var el = _.e("CreditShow_id");
		el.innerHTML = o;
	},
	//销售记录
	salecredit:function()
	{
		(new Json()).load(url.en({Pact:"htmlTemExchangeLog",id:id},"shop/dwr.php"),"oPLoad.callback_salecredit");
	},
	callback_salecredit:function(o)
	{
		var el = _.e("htmlTemExchangeLog");
		var el_dwNumSell = _.e("el_dwNumSell");
		var el_dwNum_dwNumSell = _.e("el_dwNum_dwNumSell");
		el_dwNumSell.innerHTML = 0;
		el_dwNum_dwNumSell.innerHTML = 12;
		el.innerHTML = o;
	},
	//出价记录
	salelog:function()
	{
		(new Json()).load(url.en({Pact:"htmlTemExchangeLog",id:id},"shop/dwr.php"),"oPLoad.callback_salelog");
	},
	callback_salelog:function(o)
	{
		var el = _.e("htmlTemExchangeLog");
		var el_dwNumSell = _.e("el_dwNumSell");
		var el_dwNum_dwNumSell = _.e("el_dwNum_dwNumSell");
		el_dwNumSell.innerHTML = 0;
		el_dwNum_dwNumSell.innerHTML = 12;
		el.innerHTML = o;
	},
	//卖家信息
	shopinfo:function()
	{
		(new Json()).load(url.en({Pact:"shopinfo",urs:_oPct_.urs},"shop/dwr.php"),"oPLoad.callback_shopinfo");
	},
	callback_shopinfo:function(o)
	{
		var el = _.e("info_urs");
		var rs = [];
		rs.push('<div class="titleUrs"><b>卖家信息</b></div>');
		rs.push('<div class="UserInfo">');
			rs.push('<div><img src="'+__scfg__.staticUrl+'imgs/contactNotice.gif" /></div>');
			rs.push('<div>咨询卖家： <span align="left"> '+IM(o.im).join(' ')+' </span></div>');
			rs.push('<div>最近登录： '+_.time(o.last_time,1)+'</div>');
			rs.push('<div>卖家信用： <span class="number b orange"> '+o.saleCredit+' </span></div>');
			rs.push('<div>注册时间：<span class="number orange"> '+_.time(o.save_time,1)+' </span></div>');
			//rs.push('<!--div>特殊荣誉： </div-->');
			rs.push('<div><a href="'+o.shop+'" target="_blank"> <img src="'+__scfg__.staticUrl+'imgs/info_btn_shop_big.gif" width="125" height="29" /> </a></div>');
		rs.push('</div>');
		el.innerHTML = rs.join('');
	},
	//人气
	times:function()
	{
		(new Json()).load(url.en({id:id},"stat/pct.php"),"oPLoad.callback_times");
	},
	callback_times:function(o)
	{
		o = o || {};
		var el = _.e("el_visitCount");
		el.innerHTML = o.times || '加载中..';
	},
	//刷新价格
	price:function()
	{
		(new Json()).load(url.en({Pact:"priceRefresh",id:id,r:_.rand()},"shop/dwr.php"),"oPLoad.callback_price");
	},
	callback_price:function(o)
	{
		o = o || {};
		if(o.price)
		{
			$("#html_tem_price")
			.add("#el_dwPrice_bin")
			.html(o.price || '加载中..');
		}
	},
	//免责声明
	payment:function()
	{
		var el = _.e("PayMent");
		var rs = ['<div class="title">',
				 	'<div class="TitleInfo"> 付款方式 </div>',
				 	'<div class="TitleTop"><a href="#top"></a></div>',
				 '</div>',
				 '<div id="paymentPailepay">',
				 	'<div class="payItem">收款、付款，支付注意安全。<a href="http://bbs.pailego.com/viewthread.php?tid=10&extra=page%3D1" target="_blank">点此浏览购物演示>></a></div>',
				 	'<div class="payImg"><a href="http://bbs.pailego.com/viewthread.php?tid=10&extra=page%3D1" target="_blank"><img src="'+__scfg__.staticUrl+'imgs/flow.gif" border="0"></a></div>',
				 	'<div class="payHelp desc"> <b>帮助：</b><br>',
				 		'1) <a href="http://bbs.pailego.com/viewthread.php?tid=12&extra=page%3D1" target="_blank">轻松观看“购物-付款-收货”全过程（多图）</a><br>',
				 	' </div>',
				'</div>',
				'<div id="Declare" class="relative">',
					'免责声明：本网站为用户展示的商品供求信息由买卖双方自行提供，其真实性、准确性和合法性由信息发布人负责。本网站不提供任何保证，并不承担任何法律责任。<br />',
					'<div class="note">',
						'<img src="'+__scfg__.staticUrl+'imgs/report.gif" hspace="5" align="absmiddle"> <a href="http://bbs.pailego.com/viewthread.php?tid=11&extra=page%3D1"target="_blank"> 举报不良信息 </a> ',
					'</div>',
				'</div>',
				'<div class="clear"></div>'];
		el.innerHTML = rs.join('');
	} 
}